//
//  NEDRouter.h
//  MoreCoin
//
//  Created by 林宁宁 on 2019/9/19.
//  Copyright © 2019 MoreCoin. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "UIViewController+NEDRouter.h"
#import "UIViewController+NEDRouterParame.h"

NS_ASSUME_NONNULL_BEGIN

/// 自定义操作的handle回调
typedef void (^ _Nullable NEDRouterHandleBlock)(NSDictionary * passParams);

/// 获取应用当前的控制器
UIViewController * _Nullable NEDCurrentViewController(void);
UINavigationController * NEDCurrentNavigationViewController(void);

/// 链接参数信息
NSMutableDictionary * NEDRouterParseComponentParams(NSString * urlString);

#pragma mark - -------------------

typedef NS_ENUM(NSInteger, NEDRouterErrorCode) {
    /// Bifrost 注册的handle操作是空的
    NEDRouterErrorCodeBFUrlHandlerNotFound,
    /// Bifrost 找不到该module
    NEDRouterErrorCodeBFModuleNotFoundException,
    /// Bifrost 没有找到方法实现
    NEDRouterErrorCodeBFAPINotFoundException,
    /// Bifrost module注册失败
    NEDRouterErrorCodeBFFailedToRegisterModule,
    /// map Key 格式错误
    NEDRouterErrorCodeKeyMapFormatError,
    /// 没有找到导航条
    NEDRouterErrorCodeNavigationNotFound,
    /// URL跳转 Scheme不匹配
    NEDRouterErrorCodeURLSchemeMismatch,
    /// 配置 缺少 不全
    NEDRouterErrorCodeConfigIncomplete,
    /// 链接错误
    NEDRouterErrorCodeURLWrongful,
    /// 通过Key没有找到
    NEDRouterErrorCodeKeyMapNotFound,
    /// 通过className或者key没有找到class
    NEDRouterErrorCodeClassKeyNotFound,
    /// 该控制器只能有一个
    NEDRouterErrorCodeControllerSingleton,
    /// 需要登录操作
    NEDRouterErrorCodeNeedLogin,
    
    /// 配置config操作中断了跳转
    NEDRouterErrorCodeConfigOpertionBreakOff,
    /// 参数类型 有错 不是字典类型【参数可以是空的或者是字典】
    NEDRouterErrorCodeParameterTypeError,
    /// 网页打开方式block openWebViewController 未实现
    NEDRouterErrorCodeWebviewCallbackUnrealized,
};

/** 跳转路由*/
@interface NEDRouter : NSObject

/// 再传入 URL的情况下
/// 如果有设置 不是这个scheme类型 都过滤掉
/// 未 设置不做过滤
@property (copy, nonatomic) NSString * urlScheme;

/// URL 的host 在APP内处理 默认空
@property (copy, nonatomic) NSString * urlComponentsHostAppIn;
/// URL 的host 在外部打开网页 默认空
@property (copy, nonatomic) NSString * urlComponentsHostAppOut;

/// 导航条控制器 默认UINavigationController
@property (assign, nonatomic) Class navigationViewClass;
/// 控制器映射表 "viewcontrollername": @["tag1","tage2",@(1),@(100)]
/// 在+load中 通过 ned_bindKeys 绑定
@property (retain, nonatomic) NSMutableDictionary <NSString *, NSArray *> * mapKeys;
/// 通过可以绑定handle，自定义处理
@property (retain, nonatomic) NSMutableDictionary <NSString *, NEDRouterHandleBlock> * mapHandles;

/// URL中可以读取控制器page的 key 字符串信息
@property (retain, nonatomic) NSArray <NSString *>* URLPageKeypaths;


/// 异常处理
@property (copy, nonatomic) void(^errorHandler)(NEDRouterErrorCode code, NSString * exceptionDescription, NSDictionary * _Nullable paramsInfo);
/// 路由参数外部处理 进一步做特殊处理
@property (copy, nonatomic) NSDictionary *(^parameterHandler)(NSDictionary * passParams);
/// 判断路由是否可以继续下一步操作
@property (copy, nonatomic) BOOL(^continueHandler)(NSDictionary * passParams);
/// 打开网页操作
@property (copy, nonatomic) UIViewController *(^openWebViewController)(NSString * url, NSDictionary * parame);


+ (instancetype)sharedManager;

/// MARK: - Push Present

/// vcKey 是控制器的名字，或者在NEDRouter+Map中绑定的Key
+ (UIViewController *)ned_pushKey:(NSString *)vcKey;
+ (UIViewController *)ned_pushKey:(NSString *)vcKey params:(NSDictionary * _Nullable)params;

+ (UIViewController *)ned_presentKey:(NSString *)vcKey;
+ (UIViewController *)ned_presentKey:(NSString *)vcKey params:(NSDictionary * _Nullable)params;

/// MARK: -

+ (void)ned_presentViewController:(UIViewController *)vc;
+ (void)ned_pushViewController:(UIViewController *)vc;

/// MARK: - URL
/// 通过URL跳转 内部含 控制器名称的参数信息 跳转page
/// URL:
/// https://host?page=helpCenter
/// Scheme:
/// [NEDRouter ned_openLink:@"mocr://quick?id=12&type=22"];  quick是key
/// scheme://keypayge?param1=1&param2=2
+ (UIViewController *)ned_openLink:(NSString *)URL;
+ (UIViewController *)ned_openLink:(NSString *)URL appendParams:(NSDictionary * _Nullable)appendParams;

@end

NS_ASSUME_NONNULL_END
